import path from "path"
import fs from "fs-extra"

import { desktopPath } from "@/utils"

import * as glob from "glob"
import dayjs from "dayjs"

const historyClean = () => {
  const historyPattern = path.join(desktopPath, "history/*/")

  const courses = glob.sync(historyPattern, { windowsPathsNoEscape: true })

  courses.forEach(coursePath => {
    const historyDate = path.basename(coursePath)

    const diffDay = dayjs().diff(historyDate, "day")

    diffDay > 2 && fs.rmSync(coursePath, { force: true, recursive: true })
  })
}

export default historyClean
